package com.mvc4g.example.client.view;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.mvc4g.client.Controller;
import com.mvc4g.client.ViewInterface;

public class MainView extends Composite implements ViewInterface {
	
	private Label message = new Label();
	private SimplePanel bodyPanel = new SimplePanel();
	
	public MainView(){
		VerticalPanel mainPanel = new VerticalPanel();
		mainPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		mainPanel.add(message);
		mainPanel.add(bodyPanel);		
		message.setVisible(false);
		RootPanel.get().add(mainPanel);
	}

	@Override
	public void setController(Controller controller) {
		//Nothing to do
	}
	
	public void changePage(Widget page){
		page.setVisible(true);
		bodyPanel.clear();
		bodyPanel.add(page);		
	}
	
	public void displayMessage(String message){
		this.message.setText(message);
		this.message.setVisible(true);
	}
	
	public void hideMessage(){
		this.message.setVisible(false);
	}
}
